package com.example.gpstest.activity;

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.location.GnssMeasurement;
import android.location.GnssMeasurementsEvent;
import android.location.GnssStatus;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;

import com.example.gpstest.R;
import com.example.gpstest.Utils.SHA;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.interfaces.OnConfirmListener;

import java.text.DecimalFormat;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

@RequiresApi(api = Build.VERSION_CODES.N)
public class MainActivity extends AppCompatActivity {
    private static final String[] INITIAL_PERMS = {
            Manifest.permission.ACCESS_FINE_LOCATION,
            Manifest.permission.READ_CONTACTS,
            Manifest.permission.WRITE_EXTERNAL_STORAGE
    };
    private static final int INITIAL_REQUEST = 1337;
    @BindView(R.id.btn_ttff)
    Button btnTtff;
    @BindView(R.id.btn_Search_Snr)
    Button btnSearchSnr;
    @BindView(R.id.btn_Search_Star)
    Button btnSearchStar;
    @BindView(R.id.btn_road_test)
    Button btnRoadTest;
    private Button btn_Version;
    @SuppressLint("NewApi")
    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            requestPermissions(INITIAL_PERMS, INITIAL_REQUEST);
        }
        btn_Version = findViewById(R.id.btn_version);
        String versionName = SHA.getVersionName(this);
        btn_Version.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new XPopup.Builder(MainActivity.this).asConfirm("关于我们", "版本号："+versionName,
                        new OnConfirmListener() {
                            @Override
                            public void onConfirm() {
                            }
                        })
                        .show();
            }
        });
    }

    @OnClick({R.id.btn_ttff, R.id.btn_Search_Snr, R.id.btn_Search_Star, R.id.btn_road_test})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_ttff:
                //TTFF
                Intent intent = new Intent(MainActivity.this, GpsTtffActivity.class);
                startActivity(intent);
                break;
            case R.id.btn_Search_Snr:
                //SNR
                Intent intent1 = new Intent(MainActivity.this, GPSSnrActivity.class);
                startActivity(intent1);
                break;
            case R.id.btn_Search_Star:
                //搜星区间
                Intent intent2 = new Intent(MainActivity.this, GPSStarInterval.class);
                startActivity(intent2);
                break;
            case R.id.btn_road_test:
                //路测
                Intent intent4 = new Intent(MainActivity.this, GPSGoogleEarthActivity.class);
                startActivity(intent4);
                break;
        }
    }
}
